package com.zhengxyou.jetpackdemo.lifecycle_liveData_viewModel.lifecycle;

import android.util.Log;

import com.zhengxyou.jetpackdemo.lifecycle_liveData_viewModel.LifecycleLiveDataViewModelActivity;

import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;

/**
 * Lifecycle的2种实现方式的第2种，推荐这种方式
 * <p>
 * 第一步：通过实现{@link DefaultLifecycleObserver}接口，复写想要监听的生命周期
 * 第二步：和第一种实现方式一样，都是通过getLifecycle().addObserver方法在组件那添加这个观察者
 *
 * @see LifecycleLiveDataViewModelActivity#addLifecycleObserver()
 * </p>
 * <p>
 * {@link LifecycleOwner}为生命周期所有者即被观察者，Activity或者Fragment<br>
 * DefaultLifecycleObserver的父类也是{@link LifecycleObserver}
 * </p>
 */
public class MyConnectListenerByDefault implements DefaultLifecycleObserver {
    private String TAG = "TAG";

    @Override
    public void onCreate(@NonNull LifecycleOwner owner) {
        Log.e(TAG, "onCreate");
    }

    @Override
    public void onStart(@NonNull LifecycleOwner owner) {
        Log.e(TAG, "onStart");
    }

    @Override
    public void onResume(@NonNull LifecycleOwner owner) {
        Log.e(TAG, "onResume");
    }

    @Override
    public void onPause(@NonNull LifecycleOwner owner) {
        Log.e(TAG, "onPause");
    }

    @Override
    public void onStop(@NonNull LifecycleOwner owner) {
        Log.e(TAG, "onStop");
    }

    @Override
    public void onDestroy(@NonNull LifecycleOwner owner) {
        Log.e(TAG, "onDestroy");
    }
}
